import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.link.IssueLinkManager
import com.atlassian.jira.user.ApplicationUser

IssueManager issueManager = ComponentAccessor.getIssueManager()
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
IssueLinkManager issueLinkManager = ComponentAccessor.getIssueLinkManager()
ApplicationUser remoteUser = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

Issue issue = issueManager.getIssueObject("IPD-43")

// 获取当前Issue类型
String issueTypeId = issue.getIssueType().getId()
// 如果是Story，取关联Feature
if ("10101".equals(issueTypeId)) {
    CustomField feature = customFieldManager.getCustomFieldObject("customfield_11502")
    Long srcIssueId = ((Issue) issue.getCustomFieldValue(feature)).getId()
    Long destIssueId = issue.getId()
    Long issueLinkTypeId = 10003
    Long sequence = null

    issueLinkManager.removeIssueLinks(issue, remoteUser)
    issueLinkManager.createIssueLink(srcIssueId, destIssueId, issueLinkTypeId, sequence, remoteUser)
}
// 如果是Feature，取关联Epic
else if ("10200".equals(issueTypeId)) {
    CustomField epic = customFieldManager.getCustomFieldObject("customfield_11606")
    Long srcIssueId = ((Issue) issue.getCustomFieldValue(epic)).getId()
    Long destIssueId = issue.getId()
    Long issueLinkTypeId = 10003
    Long sequence = null

    issueLinkManager.removeIssueLinks(issue, remoteUser)
    issueLinkManager.createIssueLink(srcIssueId, destIssueId, issueLinkTypeId, sequence, remoteUser)
}
// 其他类型，暂不处理
else {

}